package com.rybbaby.tss.platform.tags;

import java.util.List;

import com.rybbaby.tss.core.utils.SpringApplicationContextUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.ConfigurableApplicationContext;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

/**
 * @description 自定义freemarker标签，获取spring容器中的对象
 * 
 * @author 谢进伟
 * 
 * @createDate 2016-1-26 上午10:01:39
 */
public class GetSpringApplicationBean implements TemplateMethodModelEx {
	
	@Override
	@SuppressWarnings("rawtypes")
	public Object exec(List args) throws TemplateModelException {
		String beanid = (String)args.get(0);
		if(StringUtils.isEmpty(beanid)) {
			throw new TemplateModelException("标签beanid参数不能为空");
		}
		ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) SpringApplicationContextUtil.getContext();
		Object obj = applicationContext.getBean(beanid);
		return obj;
	}
	
}
